package com.renhui.videoplayer;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import java.util.Formatter;
import java.util.Locale;

/**
 * Created by Nathen On 2016/02/21 12:25
 */
public class VideoUtils {

	public static String stringForTime(int timeMs) {
		if (timeMs <= 0 || timeMs >= 24 * 60 * 60 * 1000) {
			return "00:00";
		}
		int totalSeconds = timeMs / 1000;
		int seconds = totalSeconds % 60;
		int minutes = (totalSeconds / 60) % 60;
		int hours = totalSeconds / 3600;
		StringBuilder stringBuilder = new StringBuilder();
		Formatter mFormatter = new Formatter(stringBuilder, Locale.getDefault());
		String timeStr = "";
		if (hours > 0) {
			timeStr = mFormatter.format("%d:%02d:%02d", hours, minutes, seconds).toString();
		} else {
			timeStr = mFormatter.format("%02d:%02d", minutes, seconds).toString();
		}
		mFormatter.close();
		return timeStr;
	}

	public static boolean isWifiConnected(Context context) {
		ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
		@SuppressWarnings("deprecation")
		NetworkInfo wifiNetworkInfo = connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
		if (wifiNetworkInfo.isConnected()) {
			return true;
		}
		return false;
	}

}
